<!DOCTYPE html>
<html>
	<head>
		<meta charset="utf-8">
		<title></title>
	</head>
	<body>
		
		
		<script type="text/javascript">
			
		/*	
			
			//1.创建字符串
			var str1 = new String("123");
			//var str2 = new "abc";
			
			
			//2.属性
			
			console.log(str1.length);
			
			//prototype属性
			String.prototype.getLength = function(){
				return this.length;
			}
			var str3 = new String("abcdef");
			console.log(str1.getLength());
			
			//constructor属性
			
			//3.操作
			
			//查找字符串
			var str4 = "aa2131313a";
			
			console.log(str4.charAt(4));
			
			for(var i = 0;i<str4.length;i++)
			{
				
				console.log(str4.charAt(i))
				
			}
			
			var str5 = "hello world,酸萝卜别吃,world"
			console.log(str5.indexOf("world"));
			console.log(str5.indexOf("酸萝卜"));
			console.log(str5.lastIndexOf("world"));
			console.log(str5.indexOf("world"));
			
			
			
			//3.2截取
			//slice(开始的下标，中止的下标)
			//substr(开始的下标，截取的长度)
			//substring(开始的下标，中止的下标)
			
			
			var str6 = "adsada333dwdad";
			console.log(str6.slice(3,3+5));
			console.log(str6.substr(4,8));
			console.log(str6.substring(5,9));
		
			function foo1(path){
				
				//查找最后一个/的位置
				var pos = path.lastIndexOf("/");
				//截取路径
				var tempPath = path.substr(0,pos+1);
				console.log(tempPath);
				//截取文件名
				var filename = path.substr(pos+1,path.length);
				console.log(filename);
				
				pos  = filename.indexOf(".");
				
			//	var nam1 = filename.substr(0.pos);
			//	console.log(nam1);
				
				var ext = filename.substr(pos,filename.length);
				console.log(ext);
			}
			
			
			
			
				// 用如下代码测试:			
				var filePath = "d:/abc/aaa/temp1.txt";
				foo1(filePath);
				filePath = "c:/1.txt";
				foo1(filePath);
				filePath = "e:/资料/2.html";
				foo1(filePath);
		
		
		
		
		function foo2(path) 
		{
			const pathParts = path.split('/');//截取/
			const filename = pathParts.pop(); // 获取文件名
			const directoryPath = pathParts.join('/'); // 获取目录路径
 
			console.log('路径信息:', directoryPath);
			console.log('文件名:', filename);
			console.log('后缀:', filename.split('.').pop());
			
		}
			// 示例使用
			foo2('d:/abc/aaa/temp1.txt');
			
			
			//大小写转换
			var str = "123213sadsadsadsa";
			console.log(str.toLowerCase());
			console.log(str.toUpperCase());
			
			//字符串连接与分割
			var st1 = "abc";
			var st2 = "dsv";
			var st3 = "fgfg";
			console.log(st1.concat(st2,st3));
			
			var st4 = "sdasdsadsadsadsad,asdaad,dddasd,vvvv";
			var starr = st4.split(",");
			console.log(starr);
						
						// 练习2
						// 将以下信息分割放入对象数组
						// 1,张三,18;2,李四,20;3,王五,21
						
						// var stu={}
						// stu.id= 
						// stu.name=
						// stu.age = 
						
						// var stus=[];
						// stus[0] = stu;
			*/
		   
			var stus=[];
			var infoStr = "1,张三,18;2,李四,20;3,王五,22";
			var infoArr = infoStr.split(";");
				
			for(var i = 0; i<infoArr.length;i++)
			{
				var info = infoArr[i];
				console.log(info);
				
				var stuInfoArr = info.split(",");
				console.log(stuInfoArr);
				
				//拆分
				var stu={}
				stu.id = stuInfoArr[0];
				stu.name = stuInfoArr[1];
				stu.age = stuInfoArr[2];
				
				
				stus[i] = stu ;
				
				
			}	
			console.log(stus);
		
		
			
		</script>
	</body>
</html>
